<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>05</title>
</head>
<body>
<input type="text" placeholder="编号" id="i1">
<input type="text" placeholder="价格" id="i2">
<input type="text" placeholder="项目" id="i3">
<input type="button" value="添加" onclick="f()">
<table border="1">
  <caption>消费明细</caption>
  <tr>
    <td>编号</td>
    <td>价格</td>
    <td>项目</td>
  </tr>
</table>

<script>
    function f() {
        // 1.创建tr
        let tr = document.createElement("tr");
        // 2.创建3个td
        let nameTd = document.createElement("td");
        let salaryTd = document.createElement("td");
        let jobTd = document.createElement("td");
        // 3.得到3个文本框并把3个文本框的值给到3个td
        nameTd.innerText = i1.value;
        salaryTd.innerText = i2.value;
        jobTd.innerText = i3.value;
        //4. 把td装进tr
        tr.append(nameTd, salaryTd, jobTd);
        //5. 得到table  并把tr装进table
        let table = document.querySelector("table");
        table.append(tr)
    }
</script>

</body>
</html>